package cn.star.jots.subjectSort.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.subjectSort.pojo.dto.SubjectSortQuery;
import cn.star.jots.subjectSort.pojo.dto.SubjectSortSaveParam;
import cn.star.jots.subjectSort.pojo.vo.SubjectSortVO;
import cn.star.jots.subjectSort.service.SubjectSortService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/subjectSort")
@Api(tags = "用户端首页专题展示")
@Slf4j

public class SubjectSortController {

    @Autowired
    SubjectSortService subjectSortService;

    @GetMapping("/select")
    @ApiOperation(value = "查询专题列表")
    public JsonResult selectAll(SubjectSortQuery subjectSortQuery) {
       log.info("查询专题列表:subjectSortQuery={}", subjectSortQuery);
        List<SubjectSortVO> list = subjectSortService.selectAll(subjectSortQuery);
        return JsonResult.ok(list);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据ID删除专题")
    public JsonResult deleteById(@PathVariable Long id) {
        log.info("根据ID删除专题:id={}", id);
        subjectSortService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存专题")
    public JsonResult save(SubjectSortSaveParam subjectSortSaveParam) {
        log.info("保存专题:subjectSortSaveParam={}", subjectSortSaveParam);
        subjectSortService.save(subjectSortSaveParam);
        return JsonResult.ok();
    }
}
